#include <iostream>
#include <cstring>
#include "month.h"

using namespace std;

int month::convert_month_char ( char a[]){
	if ( strcmp(a,"jan") == 0) return 1;
	if ( strcmp(a,"feb") == 0) return 2;
	if ( strcmp(a,"mar") == 0) return 3;
	if ( strcmp(a,"apr") == 0) return 4;
	if ( strcmp(a,"may") == 0) return 5;
	if ( strcmp(a,"jun") == 0) return 6;
	if ( strcmp(a,"jul") == 0) return 7;
	if ( strcmp(a,"aug") == 0) return 8;
	if ( strcmp(a,"sep") == 0) return 9;
	if ( strcmp(a,"oct") == 0) return 10;
	if ( strcmp(a,"nov") == 0) return 11;
	if ( strcmp(a,"dec") == 0) return 12;
	return 0;
}
char* month::convert_month_int (int a){
	char month[4];
	if ( a == 1) strcpy(month, "jan");
	if ( a == 2) strcpy(month, "feb");
	if ( a == 3) strcpy(month, "mar");
	if ( a == 4) strcpy(month, "apr");
	if ( a == 5) strcpy(month, "may");
	if ( a == 6) strcpy(month, "jun");
	if ( a == 7) strcpy(month, "jul");
	if ( a == 8) strcpy(month, "aug");
	if ( a == 9) strcpy(month, "sep");
	if ( a == 10) strcpy(month, "oct");
	if ( a == 11) strcpy(month, "nov");
	if ( a == 12) strcpy(month, "dec");
	return month;
}
month::month(){
	this->mon = 1;
}
month::month ( char a[]){
	this->mon = convert_month_char(a);
}
month::month (int a){
	this->mon = a;
}
void month::set_month_int (){
	int a;
	do{
		cout << "Month (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) = ";
		cin >> a;
	} while ( a > 12 || a < 1);
	this->mon = a;
}
void month::set_month_char (){
	int month;
	do{
		cout << "Month (jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec):";
		char a[4];
		fflush(stdin);
		cin.getline(a,4);
		month = convert_month_char(a);
	} while ( month == 0);
	this->mon = month;
}
void month::show_month_int(){
	cout << this->mon << endl;
}
void month::show_month_char(){
	char t[4];
	strcpy(t, convert_month_int(this->mon));
	cout << t << endl;
}
month month::next_month(){
	month t;
	if ( this->mon < 12) t.mon = this->mon + 1;
	if ( this->mon == 12) t.mon = 1;
	return t;
}